import { SHOW_ALERT, HIDE_ALERT } from './actionType'
const defaultValue = {
    // alert的类型
    alertType: 'error',
    // alert的错误信息 error ,warning, info, success
    alertMsg: '123',
    // 是否显示
    alertShow: false
}
// 使用reducer
const reducer = (state = defaultValue, action) => {
    // 深拷贝一份数据
    const newState = JSON.parse(JSON.stringify(state))
    // 判断派送过来的action
    switch (action.type) {
        // 显示警示框
        case SHOW_ALERT:
            newState.alertShow = true;
            newState.alertMsg = action.value.msg;
            newState.alertType = action.value.type;
            break;
        // 隐藏警示框
        case HIDE_ALERT:
            newState.alertShow = false
            break;
        default:
            break;
    }
    return newState
}
export default reducer